﻿using System.Collections;
using System.Collections.Generic;
using GameFramework.Fsm;
using UnityEngine;

namespace StarForce {
    public class CardDrawState : BasicCardState
    {
        private Vector3 StartScale { get; set; }
        public CardDrawState(Card handler,UiCardParameters parameters) : base(handler, parameters) {
            
        }

        private void CachePreviousValue() {
            StartScale = Hander.transform.localScale;
            Hander.transform.localScale *= Parameters.StartSizeWhenDraw;
        }

        private void SetScale() => Hander.ScaleTo(StartScale, Parameters.ScaleSpeed);

        private void GotoIdle() => ChangeState<CardIdleState>(Fsm);

        protected override void OnEnter(IFsm<Card> fsm) {
            base.OnEnter(fsm);
            CachePreviousValue();
            SetScale();
            Hander.Movement.OnFinishMotion += GotoIdle;
        }

        protected override void OnLeave(IFsm<Card> fsm, bool isShutdown) {
            Hander.Movement.OnFinishMotion -= GotoIdle;
            base.OnLeave(fsm, isShutdown);
        }
    }
}
